import React from 'react';
import { Button, message, Row, Col, Modal } from 'antd';
import { WeaErrorPage, WeaTools, WeaDialog, WeaRightMenu, WeaMoreButton, WeaSearchGroup, WeaFormItem, WeaInput, WeaTextarea,WeaLocaleProvider } from 'ecCom';
const getLabel = WeaLocaleProvider.getLabel;
//门户组件
class ElementTemplate extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            visible: false,
            title:getLabel(386539, '元素模板'),
            templateTitle: props.templateTitle,
            desc: '',
            loading: false
        }
        this.onShow = this.onShow.bind(this);
        this.onSave = this.onSave.bind(this);
        this.getButtons = this.getButtons.bind(this);
        this.getRightMenus = this.getRightMenus.bind(this);
    }
    onShow(){
        this.setState({visible:true});
    }
    onSave(){
        this.setState({loading: true})
        const { eid, onSave } = this.props;
        const { templateTitle, desc } = this.state;
        if(!templateTitle.trim()){
            Modal.error({
                title: getLabel(15172, '系统提示'),
                content: getLabel(15859, '必要信息不完整！'),
            });
            return;
        }
        onSave({type:'save&saveTemplate',templateTitle,desc});
    }
    getButtons(){
        const { loading } = this.state;
        let btns = [];
        btns.push(<Button ecId={`${this && this.props && this.props.ecId || ''}_Button@v1qktw`} disabled={loading} type="primary" onClick={this.onSave}>{getLabel(30986, '保存')}</Button>);
        btns.push(<WeaMoreButton ecId={`${this && this.props && this.props.ecId || ''}_WeaMoreButton@cylwpy`} datas={this.getRightMenus()}/>);
        return btns;
    }
    getRightMenus(){
        let btns = [];
        btns.push({
            key: '1',
            icon: <i className='icon-coms-Preservation'/>,
            content:getLabel(30986, '保存'),
            onClick: this.onSave
        });
        return btns
    }
    render() {
        const { visible, title, templateTitle, desc, loading } = this.state;
        return (<WeaDialog ecId={`${this && this.props && this.props.ecId || ''}_WeaDialog@p5m7wf`}
                    title={title}
                    visible={visible}
                    closable={true}
                    loading={loading}
                    onCancel={() => this.setState({visible:false})}
                    icon='icon-coms-portal'
                    iconBgcolor='#1a57a0'
                    maskClosable={false}
                    buttons={this.getButtons()}
                    style={{width:600}}>
                    <WeaRightMenu ecId={`${this && this.props && this.props.ecId || ''}_WeaRightMenu@eeaph1`} datas={this.getRightMenus()}>
                        <div className="portal-form-group">
                            <WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@bpo41k`} label={getLabel(386540, '模板标题')} labelCol={{span: 6}} wrapperCol={{span: 18}}>
                                <WeaInput ecId={`${this && this.props && this.props.ecId || ''}_WeaInput@al81ma`} inputType="multilang" isBase64={true} value={templateTitle} viewAttr={3} onChange={value=>this.setState({templateTitle: value})}/>
                            </WeaFormItem>
                            <WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@leu7xi`} label={getLabel(433, '描述')} labelCol={{span: 6}} wrapperCol={{span: 18}}>
                                <WeaTextarea ecId={`${this && this.props && this.props.ecId || ''}_WeaTextarea@977hbo`} value={desc} minRows={4} onChange={value=>this.setState({desc: value})}/>
                            </WeaFormItem>
                        </div>
                    </WeaRightMenu>
                </WeaDialog>
        )
    }
}
class MyErrorHandler extends React.Component {
    render() {
        const hasErrorMsg = this.props.error && this.props.error !== "";
        return ( <WeaErrorPage ecId={`${this && this.props && this.props.ecId || ''}_WeaErrorPage@sljhoc`} msg={ hasErrorMsg ? this.props.error : getLabel(385218,"对不起，该页面异常，请联系管理员！") }/>
        );
    }
}
ElementTemplate = WeaTools.tryCatch(React, MyErrorHandler, {error: ""})(ElementTemplate);
export default ElementTemplate;




